import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {BakeBeanSort} from '../../../../model/BakeBeanSort';
import {NzModalService} from 'ng-zorro-antd/modal';
import {BeansorteditComponent} from '../beansortedit/beansortedit.component';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-beansortlist',
  templateUrl: './beansortlist.component.html',
  styleUrls: ['./beansortlist.component.css']
})
export class BeansortlistComponent implements OnInit {
  sl:Array<BakeBeanSort>;
  constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef,
              private adminService:AdminService,private alertService:AlertService) {
    this.sl=new Array<BakeBeanSort>();
    this.initData();
  }

  ngOnInit(): void {
    this.initData();
  }


  initData(){
this.adminService.getEncapsorts().then((data:any)=>{
  if(data.msg == "ok"){
    this.sl = data.list
  }else{
    this.alertService.showError("获取分拣失败")
  }
})
  }



  sign(id:string){

    const modalwindow= this.modal.create({
      nzTitle: '咖啡分拣损耗信息编辑',
      nzContent: BeansorteditComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzComponentParams: {
      id:id
      },

      nzOnOk:()=>new Promise(resolve => {
        let temp=modalwindow.getContentComponent().b;
        /*if(!temp.scdsl){
          this.alertService.showWarning('色差豆数量必填');
          resolve(false)
        }else if(!temp.ccdsl){
          this.alertService.showWarning('残次豆数量必填');
          resolve(false)
        }else if(!temp.mbdsl){
          this.alertService.showWarning('霉变豆数量必填');
          resolve(false)
        }else */if(!temp.hgsl){
          this.alertService.showWarning('合格豆数量必填');
          resolve(false)
        }
        else {
          modalwindow.getContentComponent().save();
          setTimeout(()=>{

            resolve(true);
            this.initData();
            //this.getEmpDetailByEmpid(this.empid);
            //this.loadEmpImg();
          }, 1000)
        }

      })
    })

  }

  getEncapsortByClqk(c:string){
    console.dir(c)
    this.adminService.getEncapsortByClqk(c).then((data:any)=>{
      if(data.msg == "ok"){
        this.sl = data.list
      }else{
        this.alertService.showError("根据处理情况获取检验失败")
      }
    })
  }


}
